package com.study.framework;

import org.openqa.selenium.By;

public class NavigationHelper extends HelperBase {

	public NavigationHelper(ApplicaionManager mananger) {
		super(mananger);
	}

	public void groupsPage() {
		if (!onGroupsPage())
			click(By.linkText("groups"));
	}

	private boolean onGroupsPage() {
		if (driver.getCurrentUrl().contains("/group.php")
				&& driver.findElements(By.name("new")).size() > 0) {
			return true;
		} else {
			return false;
		}
	}

	public void contactsList() {
		if (onEditContactPage())
			click(By.xpath("//div[@class='msgbox']//a[contains (text(), 'home page')]"));
	}

	private boolean onEditContactPage() {
		if (driver.getCurrentUrl().contains("/edit.php") || driver.findElements(By.xpath("//div[@class='msgbox']")).size() > 0) {
			return true;
		} else {
			return false;
		}
	}

	public void mainPage() {
		if (!onMainPage()) {
			click(By.xpath("//div[@id='nav']//a[contains (text(),'home')]"));
		}
	}

	private boolean onMainPage() {
		if (driver.getCurrentUrl().contains("/")
				&& driver.findElements(By.name("searchstring")).size() > 0) {
			return true;
		} else {
			return false;
		}
	}
}
